package io.renren.controller;

import io.renren.annotation.LoginUser;
import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.utils.Result;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.DefaultGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.dto.*;
import io.renren.entity.UserEntity;
import io.renren.service.AuxiliaryMaterialsmxService;
import io.renren.service.FinanceService;
import io.renren.service.SmallCanteenPurchasemxService;
import io.renren.service.StockOrdermxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 财务记录表
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-12-04
 */
@RestController
@RequestMapping("api/finance")
@Api(tags="财务记录表")
public class FinanceController {
    @Autowired
    private FinanceService financeService;
    @GetMapping("page")
    @ApiOperation("查询所有的订单")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    public Result<PageData<FinanceDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<FinanceDTO> page = financeService.page(params);

        return new Result<PageData<FinanceDTO>>().ok(page);
    }
    /**
     * 未结算列表使用
     * 根据状态0未结算 或者1已结算 查询订单（创建时间，创建人，审核人）
     * @param dto
     * @return
     */
    @PostMapping("/selectFinance")
    @ApiOperation("订单状态信息列表")
    public Result<Map> selectFinance(@RequestBody FinancemxDTO dto){
        HashMap<String, Object> map = financeService.selectFinance(dto);
        return new Result<Map>().ok(map);
    }
    /**
     * 结算列表使用
     * 根据状态0未结算 或者1已结算 查询订单详情商品名，单价，数量，单位
     * @param dto 类型 订单 供应商id
     * @param dto
     * @return
     */
    @PostMapping("/selectFinancemx")
    @ApiOperation("订单状态信息祥情列表")
    public Result<List<FinancemxDTO>> selectFinancemx(@RequestBody FinanceDTO dto){
        List<FinancemxDTO> list = financeService.selectFinancemx(dto);
        return new Result<List<FinancemxDTO>>().ok(list);
    }

    /**
     * 财务首页使用
     * 根据状态展示所有供应商待支付或者已支付的订单总量
     * @param dto  支付状态
     * @return
     */
    @PostMapping("/selectSupplierFinance")
    @ApiOperation("供应商订单待支付总量")
    public Result<List<FinanceDTO>> selectSupplierFinance(@RequestBody FinanceDTO dto){
        List<FinanceDTO> list = financeService.selectSupplierFinance(dto);
        return new Result<List<FinanceDTO>>().ok(list);
    }
    /**
     * 财务首页使用
     * 总订单数 ，根据状态0未结算的所有订单，1已结算左右订单 查询订单
     * @param
     * @return
     */
    @PostMapping("/selectTotalFinance")
    @ApiOperation("订单总数(已支付待支付总量)信息")
    public Result<FinanceDTO> selectTotalFinance(){
        FinanceDTO financeDTO = financeService.selectTotalFinance();
        return new Result<FinanceDTO>().ok(financeDTO);
    }
    /**
     * 订单号和状态 支付金额
     * @param dto
     * @param entity
     * @return
     */
    @PostMapping("adminUpdate")
    @ApiOperation("支付接口")
    public Result updateExam(@RequestBody FinancemxDTO dto, @LoginUser UserEntity entity){
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
        return   financeService.updateExamine(dto,entity);
    }

    /**
     * 月度报表
     * @param
     * @return
     */
    @PostMapping("/selectFinanceStatement")
    @ApiOperation("辅材月度报表")
    public Result<List<FinanceStatementDTO>> selectFinanceStatement(){
        List<FinanceStatementDTO> list = financeService.selectFinanceStatement();
        return new Result<List<FinanceStatementDTO>>().ok(list);
    }

    /**
     * canteenId
     * @param dto
     * @return
     */
    @PostMapping("/getBatchOrder")
    @ApiOperation("批量订单")
    public Result<List<FinanceDTO>> getBatchOrder(@RequestBody FinanceDTO dto){
        List<FinanceDTO> date= financeService.getBatchOrder(dto);
        return new Result<List<FinanceDTO>>().ok(date);
    }
    @PostMapping("/getBatchOrderMx")
    @ApiOperation("批量订单详情")
    public Result<Map> getBatchOrderMx(@RequestBody FinanceDTO dto){
        Map date= financeService.getBatchOrderMx(dto);
        return new Result<Map>().ok(date);
    }

}